package com.citrix.gs.test.perforce;

import java.net.URISyntaxException;
import java.util.Properties;

import com.perforce.p4java.exception.AccessException;
import com.perforce.p4java.exception.ConfigException;
import com.perforce.p4java.exception.ConnectionException;
import com.perforce.p4java.exception.NoSuchObjectException;
import com.perforce.p4java.exception.RequestException;
import com.perforce.p4java.exception.ResourceException;
import com.perforce.p4java.option.UsageOptions;
import com.perforce.p4java.server.IOptionsServer;
import com.perforce.p4java.server.IServer;
import com.perforce.p4java.server.ServerFactory;

public abstract class P4JavaDemo {

    protected static String serverUri = System.getProperty("com.perforce.p4javademo.serverUri",
            "p4java://NKGP401.eng.citrite.net:2444");
    
    protected static String userName = System.getProperty("com.perforce.p4javademo.userName",
            "vincenthu");
    
    protected static String clientName = System.getProperty("com.perforce.p4javademo.clientName",
            "beacontoolcheck");
    
    protected static String password = System.getProperty(
            "com.perforce.p4javademo.password",
            "1234abcD");
    
    protected static IServer getServer(Properties props) throws ConnectionException, NoSuchObjectException, ConfigException, ResourceException, URISyntaxException, AccessException, RequestException {
        IServer server = ServerFactory.getServer(serverUri, props);
        if(server != null) {
            server.connect();
        }
        
        return server;
    }
    
    protected static IOptionsServer getOptionServer(Properties props, UsageOptions opts) throws ConnectionException, NoSuchObjectException, ConfigException, ResourceException, URISyntaxException, AccessException, RequestException {
        IOptionsServer server = ServerFactory.getOptionsServer(serverUri, props, opts);
        if(server != null) {
            server.connect();
        }
        
        return server;
    }
    
 }
